package com.sicheng.lc.周赛.分类.思维.枚举;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/2 14:18
 */
public class 统计隐藏数组数目 {
    //https://leetcode.cn/problems/count-the-hidden-sequences/
    public int numberOfArrays(int[] differences, int lower, int upper) {
        long max = 0;
        long min = 0;
        long pre = 0;
        for (int difference : differences) {
            pre += difference;
            max = Math.max(max, pre);
            min = Math.min(min, pre);
        }
        return (int) Math.max(0L, (upper - max) - (lower - min) + 1);
    }
}
